package syntelos.sx;

import alto.lang.Message;

/**
 * 
 */

public final class LogRX
    extends LogRR
{
    protected final Throwable thrown;

    public LogRX(Message.Queue queue, Request request, Response response, Throwable thrown){
        super(queue,request,response);
        if (null != thrown)
            this.thrown = thrown;
        else
            throw new IllegalArgumentException();
    }

    protected void formatRX()
        throws java.io.IOException
    {
        byte[] stacktrace = alto.lang.OutputStream.Ascii(alto.io.u.Bpo.toString(this.thrown));
        int len = ((null != stacktrace)?(stacktrace.length):(0));
        this.println(" <error content=\"stacktrace\" type=\"stream\" length=\""+len+"\">");
        this.write(stacktrace);
        if (0 < len && '\n' != stacktrace[len-1])
            this.println();
        this.println(" </error>");
    }

    public void formatMessage()
        throws java.io.IOException
    {
        this.resetall();
        this.formatRRHead();
        this.formatRX();
        this.formatRRTail();
    }
}
